---
import Layout from '@/layouts/Layout.astro';
import { SubscriptionService } from '@/lib/services/subscription';
import { CreateSubscriptionButton } from '@/components/admin/create-subscription';
import { SubscriptionsTable } from '@/components/admin/subscriptions-table';

const { API_TOKEN, DB } = Astro.locals.runtime.env;
const subscriptionService = new SubscriptionService(DB);
const subscriptions = await subscriptionService.getAll();
---

<Layout title="Subscriptions">
  {subscriptions.length ? (
    <SubscriptionsTable data={subscriptions} />
  ) : (
    <p class="font-medium text-muted-foreground">
      No subscriptions yet. Try creating one using the API or by selecting "Create New Subscription" above.
    </p>
  )}

  <div slot="actions">
    <CreateSubscriptionButton apiToken={API_TOKEN} client:only="react" />
  </div>
</Layout>
